<template>
	<avue-crud :option="option" :data="data" :page="page" v-model="form" ref="crud" @selection-change="selectionChange"
	 @search-change="searchChange" @search-reset="searchReset" @on-load="onLoad">
		<template slot-scope="{row}" slot="toQty">
			<el-input-number style="width: 100px;" size="mini" v-model="row.toQty" :min="0" :max="row.quantity" controls-position="right"></el-input-number>
		</template>
		<template slot="menuLeft">
			<el-button type="primary" size="mini" @click.stop="handleClose">确定</el-button>
		</template>
	</avue-crud>
</template>

<script>
	import request from '@/router/axios';

	export default {
		props: {
			selectionList: {},
			storeCode: ''
		},
		data() {
			return {
				selects: [],
				form: {
					toQty: 0
				},
				options: [],
				query: {},
				page: {
					pageSize: 10,
					currentPage: 1,
					total: 0
				},
				option: {
					size: "mini",
					selection: true,
					searchShow: false,
					searchMenuSpan: 6,
					border: true,
					refreshBtn: false,
					addBtn: false,
					menu: false,
					column: [{
							label: "库位",
							prop: "localCode",
							search: true
						},
						{
							label: "条码",
							prop: "barCode",
							search: true
						},
						{
							label: "库存",
							prop: "quantity",
							width: 60
						},
						{
							label: "计划移出",
							prop: "toQty",
							type: "number",
							slot: true,
							width: 130
						}
					]
				},
				data: []
			};
		},
		computed: {},
		created() {},
		mounted() {},
		methods: {
			handleClose() {
				this.$emit('closeDialog', this.selects)
			},
			selectionChange(list) {
				this.selects = list;
				//this.$emit('closeMoule', list);
			},
			searchReset() {
				this.query = {};
				this.page.currentPage = 1;
				this.onLoad(this.page);
			},
			searchChange(params, done) {
				this.query = params;
				this.page.currentPage = 1;
				this.onLoad(this.page);
				done();
			},
			onLoad(page) {
				request({
					url: '2/api/WmsInventory/getpages',
					method: 'get',
					params: {
						key: this.query.barCode == undefined ? '' : this.query.barCode,
						type: this.storeCode,
						status: this.query.localCode == undefined ? '' : this.query.localCode,
						where: this.query.matnr == undefined ? '' : this.query.matnr,
						page: page.currentPage,
						limit: page.pageSize
					}
				}).then(res => {
					const data = res.data
					data.data.forEach(ele => {
						ele.toQty = ele.quantity;
					});
					this.data = data.data;
					this.page.total = data.remark;
					// this.$nextTick(() => {
					// 	var select = [];
					// 	this.data.forEach(ele => {
					// 		this.selectionList.data.forEach(e => {
					// 			if (ele.storeCode == e.storeCode && ele.localCode == e.localCode && ele.barCode == e.barCode) {
					// 				ele.toQty = e.toQty;
					// 				select.push(ele);
					// 				return;
					// 			}
					// 		});
					// 	});
					// 	this.$refs.crud.toggleSelection(select);
					// })
				});
			}
		}
	};
</script>

<style>
	.avue-crud__menu {
		min-height: 0px;
	}

	.el-dialog__body {
		padding-top: 0px;
	}
</style>
